/*
 *  Copyright (C) 2012 Компания ВИТ. web: http://diasled.ru Е-mail:  vit@diasled.ru
 * 
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 * 
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 * 
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package ru.apertum.diasled.model.exam;

import java.awt.Color;
import java.math.BigDecimal;
import java.math.RoundingMode;
import javax.swing.table.AbstractTableModel;
import ru.apertum.diasled.cfg.ColorScale;

/**
 *
 * @author Evgeniy Egorov, Aperum Projects
 */
public class ColorIndTableModel extends AbstractTableModel {

    final ColorScale scale;
    final int max, min;

    public int getMax() {
        return max;
    }

    public int getMin() {
        return min;
    }

    public ColorIndTableModel(ColorScale scale) {
        this.max = scale.getMax();
        this.min = scale.getMin();
        this.scale = scale;
    }

    @Override
    public int getRowCount() {
        return ColorScale.DIVISIONS;
    }

    @Override
    public int getColumnCount() {
        return 3;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        switch (columnIndex) {
            case 0:
                return 0;
            case 1:
                return new Color(scale.getColors().get(rowIndex));
            case 2:
                return (new BigDecimal((scale.getMax() - rowIndex * new Double(((scale.getMax() - scale.getMin()) / ColorScale.DIVISIONS))) / 1000)).setScale(2, RoundingMode.UP);
            default:
                throw new AssertionError();
        }
    }

    @Override
    public Class<?> getColumnClass(int columnIndex) {
        switch (columnIndex) {
            case 0:
                return Integer.class;
            case 1:
                return Color.class;
            case 2:
                return Double.class;
            default:
                throw new AssertionError();
        }
    }
}
